package com.styletransfer.controller;

import com.styletransfer.model.ApiResponse;
import com.styletransfer.model.Notification;
import com.styletransfer.model.PageResponse;
import com.styletransfer.service.NotificationService;
import com.styletransfer.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 消息通知控制器
 */
@RestController
@RequestMapping("/notification")
public class NotificationController {

    @Autowired
    private NotificationService notificationService;

    @Autowired
    private UserService userService;

    /**
     * 获取当前用户的通知列表
     * @param page 页码
     * @param size 每页大小
     * @return 通知列表
     */
    @GetMapping("/list")
    public ApiResponse<PageResponse<Notification>> getNotifications(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        Long userId = userService.getCurrentUserId();
        return notificationService.getUserNotifications(userId, page, size);
    }

    /**
     * 获取当前用户的未读通知数量
     * @return 未读通知数量
     */
    @GetMapping("/unread/count")
    public ApiResponse<Integer> getUnreadCount() {
        Long userId = userService.getCurrentUserId();
        return notificationService.getUnreadCount(userId);
    }

    /**
     * 标记通知为已读
     * @param id 通知ID
     * @return 操作结果
     */
    @PostMapping("/{id}/read")
    public ApiResponse<Void> markAsRead(@PathVariable Long id) {
        Long userId = userService.getCurrentUserId();
        return notificationService.markAsRead(id, userId);
    }

    /**
     * 标记所有通知为已读
     * @return 操作结果
     */
    @PostMapping("/read/all")
    public ApiResponse<Void> markAllAsRead() {
        Long userId = userService.getCurrentUserId();
        return notificationService.markAllAsRead(userId);
    }

    /**
     * 删除通知
     * @param id 通知ID
     * @return 操作结果
     */
    @PostMapping("/{id}")
    public ApiResponse<Void> deleteNotification(@PathVariable Long id) {
        Long userId = userService.getCurrentUserId();
        return notificationService.deleteNotification(id, userId);
    }


}
